import time

import asyncio

async def work(i):
	print(f'tast {i} start')
	await asyncio.sleep(i) # 模拟IO事件
	print(f'tast {i} end')

# 创建了一个协程对象 coroutine
# print(tast(1))

start =  time.time()
# 1.构建事件循环对象
loop = asyncio.get_event_loop()

# 2.构建协程对象
works = [
	asyncio.ensure_future(work(1)),
	asyncio.ensure_future(work(2)),
]

# 3.收集任务并等待
loop.run_until_complete(asyncio.wait(works))


end = time.time()
print('耗时:', end - start)